//
//  ZCAttentionContentCell.m
//  百思不得姐
//
//  Created by Ning Xie on 16/8/24.
//  Copyright © 2016年 zhangchong. All rights reserved.
//

#import "ZCAttentionContentCell.h"
#import "ZCAttentionContentModel.h"

@interface ZCAttentionContentCell ()

@property (nonatomic, strong) UIImageView *headerImage;
@property (nonatomic, strong) UIImageView *vipImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *fansLabel;
@property (nonatomic, strong) UIButton *followButton;

@property (nonatomic, strong) UIView *lineView;


@end

@implementation ZCAttentionContentCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        self.lineView = [[UIView alloc]init];
        self.lineView.backgroundColor = ZCGlobalRBG;
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.trailing.leading.mas_equalTo(self.contentView);
            make.height.mas_equalTo(1);
        }];
    }
    return self;
}

-(void)setupUI{
    
    self.headerImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"defaultUserIcon"]];
    _headerImage.layer.cornerRadius = 20;
    _headerImage.layer.masksToBounds = YES;
    
    self.nameLabel = [[UILabel alloc]init];
    _nameLabel.font = [UIFont systemFontOfSize:15];
    [_nameLabel sizeToFit];
    _nameLabel.textAlignment = NSTextAlignmentLeft;

    self.vipImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Profile_AddV_authen"]];
    
    self.fansLabel = [[UILabel alloc]init];
    _fansLabel.font = [UIFont systemFontOfSize:14];
    [_fansLabel sizeToFit];
    _fansLabel.textAlignment = NSTextAlignmentLeft;
    _fansLabel.textColor = [UIColor grayColor];
    
    self.followButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _followButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_followButton setTitle:@"+ 关注" forState:UIControlStateNormal];
    [_followButton setTitle:@"取消关注" forState:UIControlStateSelected];
    [_followButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_followButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
    [_followButton setBackgroundImage:[UIImage imageNamed:@"FollowBtnBg"] forState:UIControlStateNormal];
    [_followButton addTarget:self action:@selector(followButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    _followButton.adjustsImageWhenHighlighted = NO;
    
    
    [self.contentView addSubview: _headerImage];
    [self.contentView addSubview:_vipImage];
    [self.contentView addSubview:_nameLabel];
    [self.contentView addSubview:_fansLabel];
    [self.contentView addSubview:_followButton];
    
    [_headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.leading.equalTo(self.contentView).offset(10);
        make.width.height.equalTo(self.contentView.mas_height).offset(-20);
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_headerImage);
        make.leading.equalTo(_headerImage.mas_trailing).offset(10);
        make.trailing.equalTo(_followButton.mas_leading);
    }];
    
    [_vipImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_nameLabel);
        make.leading.equalTo(_nameLabel.mas_trailing).offset(5);
        make.width.height.mas_equalTo(_nameLabel.mas_height);
    }];
    
    [_fansLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_headerImage);
        make.leading.equalTo(_headerImage.mas_trailing).offset(10);
    }];
    
    [self.followButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.trailing.equalTo(self.contentView).offset(-10);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
    }];
}

-(void)setModel:(ZCAttentionContentModel *)model{
    _model = model;
    
    [self.headerImage sd_setImageWithURL:[NSURL URLWithString:model.header] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
    self.fansLabel.text = [NSString stringWithFormat:@"%@人关注",model.fans_count];
    self.nameLabel.text = model.screen_name;
    self.vipImage.hidden = !model.is_vip;
    if (model.is_vip) {
        self.nameLabel.textColor = [UIColor redColor];
    }else{
        self.nameLabel.textColor = [UIColor grayColor];
    }
}

-(void)followButtonAction:(UIButton*)sender{
    
    sender.selected = ![sender isSelected];
    ZCLogFunc;
}

//-(void)setFrame:(CGRect)frame{
//    
//    
//    frame.size.height -= 1;
//    
//    [super setFrame:frame];
//}

@end
